package application;

import java.util.Date;
import java.text.SimpleDateFormat;

public class Time {
	/**
	 * @param timeStamp 时间戳
	 * @return 返回时间戳对应的"xxxx年xx月xx日"格式的字符串
	 * @author TAO
	 */
    public static String getDate(String timeStamp) {
    	if(timeStamp.equals("") || timeStamp==null || timeStamp.isEmpty() || timeStamp.equals("null")) return "未知";
    	else {
    		SimpleDateFormat SDF = new SimpleDateFormat("yyyy'年'MM'月'dd'日'");
            return SDF.format(new Date(Long.valueOf(timeStamp+"000")));
    	}
    }
    /**
     * @param delayTime 延迟的秒数(<86400)
     * @return 过了延迟的时间后返回
     * @author TAO
     */
    public static void delay(int delayTime) {
    	int beginTime=getNowTime();
    	int endTime=beginTime+delayTime;
    	while(getNowTime()<=endTime) {}
    }
    public static int getNowTime() {
    	SimpleDateFormat SDF = new SimpleDateFormat("HH:mm:ss");
    	String SDFtime=SDF.format(new Date());
    	return getHour(SDFtime)*3600+getMin(SDFtime)*60+getSec(SDFtime);
    }
    public static int getHour(String SDFtime) {
    	int hour= Integer.valueOf(SDFtime.substring(0, 2));
    	return hour;
    }
    public static int getMin(String SDFtime) {
    	int min = Integer.valueOf(SDFtime.substring(3, 5));
    	return min;
    }
    public static int getSec(String SDFtime) {
    	int sec= Integer.valueOf(SDFtime.substring(6, 8));
    	return sec;
    }
}
